package LeetCodeHot100TopInterview;


public class Q048_RotateMatrix {
    //旋转矩阵
    public void rotate(int[][] matrix) {

        int upRow = 0;
        int upCol = 0;
        int downRow = matrix.length - 1;
        int downCol = matrix[0].length - 1;
        while (upRow != downRow){
            process(matrix, upRow++, upCol++, downRow--, downCol--);
        }
    }

    public void process(int[][] matrix, int upRow, int upCol, int downRow, int downCol){

        int tmp = 0;
        //循环
        int times = downRow - upRow;
        for (int i = 0; i < times; i++) {
            tmp = matrix[upRow][upCol + i];
            matrix[upRow][upCol + i] = matrix[downRow - i][upCol];
            matrix[downRow - i][upCol] = matrix[downRow][downCol - i];
            matrix[downRow][downCol - i] = matrix[upRow + i][downCol];
            matrix[upRow + i][downCol] = tmp;
        }
    }

}
